<?php

/**
 * home actions.
 *
 * @package    LYPO
 * @subpackage home
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 9301 2008-05-27 01:08:46Z dwhittle $
 */
class homeActions extends sfActions
{

	public function preExecute(){
		if(sfConfig::get('sf_web_debug')==true){
			$this->setLayout('layout');
		}else{
			$this->setLayout(false);
		}
		$this->setTemplate('default');
	}
	/**
	 * Executes index action
	 *
	 * @param sfRequest $request A request object
	 */
	public function executeOpposites(sfWebRequest $request)
	{
		$result = new LypoResult();
		$userid = $request->getParameter('userid');
		try {
			/* @var $user User */
			$user = UserPeer::getByContainerString($userid);
			if($user){
				$this->args = array('user' => $user);
				$this->partial = 'opposites';
			}else{
				$result->setErrorMessage("User not found");
				return $this->renderText(print_r($result->toArray(),1));
			}
		}catch( Exception $e){
			$result->setErrorMessage($e->getMessage());
			return $this->renderText(print_r($result->toArray(),1));
		}
	}

	public function executeDebates(sfWebRequest $request)
	{
		$result = new LypoResult();
		$userid = $request->getParameter('userid');
		$view = $this->getRequestParameter('view');
		try {
			/* @var $user User */
			$user = UserPeer::getByContainerString($userid);
			if($user){
				$this->partial = 'debates';
				$this->args = array('userid' => $userid, 'user' => $user);
				
				$debate = LypoStatementPeer::getTodaysDebate();
				$this->args['debate'] = $debate;
				
				$myanswer = StatementAnswerPeer::ANSWER_NOANSWER;
				
				if($debate){
					//Kijken of huidige gebruiker antwoord op heeft gegeven
					$answer = StatementAnswerPeer::getStatementAnswerForUser($debate,$user);
					if ($answer) $myanswer = $answer->getAnswer();
				}
				$this->args['myanswer'] = $myanswer;
				
			}else{
				$result->setErrorMessage("User not found");
				return $this->renderText(print_r($result->toArray(),1));
			}
		}catch( Exception $e){
			$result->setErrorMessage($e->getMessage());
			return $this->renderText(print_r($result->toArray(),1));
		}
	}

}
